<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.longtop.com/intelliweb" prefix="e"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>功能列表-SJH</title>
</head>
<e:View id="view">
    <script type="text/javascript" src="<c:url value='/scripts/global.js'/>"></script>
	<script type="text/javascript" src="<c:url value='/scripts/skin.js'/>"></script>
    <script type="text/javascript">SkinUtil.getSkin();</script>
    <script type="text/javascript">SkinUtil.getModuleSkin();</script>
    
	<div id="Invisual Controls" style="min-height: 40px; background-color: LemonChiffon;" >
		<e:Dataset id="Dataset_Func" datasetDefinition="DatasetDefinition_sys.dsd" datasetRef="dataset_Func" pageSize="-1">
			<e:Field name="funcId" dataType="string" label="id" maxLength="32" />
			<e:Field name="menuId" dataType="string" label="menuId" maxLength="32" />
			<e:Field name="funcName" dataType="string" label="name" maxLength="50" />
		</e:Dataset>
		<e:Dataset id="Dataset_Menu" datasetDefinition="DatasetDefinition_sys.dsd" datasetRef="dataset_Menu" pageSize="-1"
				onAfterScroll="Dataset_Menu_onAfterScroll(dataset)">
			<e:Field name="menuId" dataType="string" label="id" maxLength="32" />
			<e:Field name="menuName" dataType="string" label="name" maxLength="100" />
			<e:Field name="parentMenuId" dataType="string" label="parentId" maxLength="32" />
		</e:Dataset>
		
		<e:Command id="Command_Load" action="com.longtop.framework.sys.func.web.FuncListAction" 
			method="loadFunc" showHintInfoOnSuccess="false">
			<e:Parameter name="menuId"></e:Parameter>
			<e:DatasetInfo name="info" dataset="Dataset_Func" alwayRefreshClient="true" submitType="none"></e:DatasetInfo>
	    </e:Command>
	    <e:Command id="Command_Save" action="com.longtop.framework.sys.func.web.FuncListAction" 
	    	method="saveFunc" onExecuteSuccess="Command_Save_onExecuteSuccess(command)" onExecuteFailure="Command_Save_onExecuteFailure(command)">
			<e:DatasetInfo name="DatasetInfo2" dataset="Dataset_Func"></e:DatasetInfo>
		</e:Command>
	</div>

<body>
	<e:Page id="ePage" action="com.longtop.framework.sys.func.web.FuncListAction" style="min-height: 80px; width: 100%; height: 100%;" onAfterLoadPage="ePage_onAfterLoadPage()">
		<table style="width: 100%; height: 100%;" border="0" cellpadding="0" cellspacing="0" width="100%" align="center">
			<tr>
				<td align="left" valign="top">
					<e:Panel id="Panel_Search" style="width: 285px; height: 100%" caption="菜单树" 
						captionIcon="/images/query_win.gif" captionStyle="color:#888888" allowFold="true" showArrowButton="false">
						<table style="text-align: left; width: 100%;" border="0" cellpadding="3" cellspacing="3" width="100%" align="center">
							<tr>
								<td align="left">
									<e:DataTree id="DataTree_Menu" dataset="Dataset_Menu" nameField="menuId" valueField="menuId"
										parentField="parentMenuId" labelField="menuName" 
										style="border-color:#3ABCFA;width: 100%; height: 420; text-align: left"
										showRoot="true" rootLabel="菜单树" lazyLoading="false" useDefaultFolderIcon="true" contextMenuItems="expand,collapse">
									</e:DataTree>
								</td>
							</tr>
						</table>
					</e:Panel>
				</td>
				<td valign="top" width="100%">
					<e:Panel id="Panel_Result" style="width: 100%; height: 100%" captionStyle="color:#888888" 
						caption="功能列表" captionIcon="/images/list_win.gif" showArrowButton="false">
						<table style="text-align: left; width: 100%;" border="0" cellpadding="3" cellspacing="3" >
							<tr>
								<td>
									<table style="text-align: left;" border="0" cellpadding="0" width="100%" cellspacing="0">
									  	<tr>
											<td height="27px" width="1%" nowrap="nowrap">
												<e:RecordNavigator id="RecordNavigator_Func" dataset="Dataset_Func" showNavigatorButton="false">
													<e:RecordButton id="RecordButton_Insert" label="新增" icon="/images/add.gif" onClick="RecordButton_Insert_onClick()"></e:RecordButton>
													<e:RecordButton id="RecordButton_Delete" label="删除" onClick="deleteRecord" icon="/images/delete.gif"></e:RecordButton>
													<e:RecordButton id="RecordButton_Save" label="提交操作" icon="/images/submit.gif" onClick="RecordButton_Save_onClick()"></e:RecordButton>
												</e:RecordNavigator>
											</td>
											<td width="99%" align="left">
												<e:PageNavigator id="PageNavigator_Func" dataset="Dataset_Func" showRecordNum="true"></e:PageNavigator>
											</td>
									  	</tr>
								  	</table>
								</td>	
							</tr>
							<tr>
								<td>
									<e:Grid id="Grid_result" style="height: 100%; width: 100%;" dataset="Dataset_Func" 
											showIndex="false" onFocusCell="Grid_result_onFocusCell(cell,value)" onClick="Grid_result_onClick()">
										<e:Column name="id" label="功能编号" field="funcId" style="width: 30%" readOnly="false" ></e:Column>
										<e:Column name="menuId" label="菜单编号" field="menuId" style="width: 30%" readOnly="true"></e:Column>
										<e:Column name="name" label="功能名称" field="funcName" style="width: 40%"></e:Column>
									</e:Grid>
								</td>	
							</tr>
							<tr>
								<td>
									<e:Label id="Label1" caption="功能编号规范：菜单编号＋冒号＋功能码；<br>
										功能码规范：&nbsp;&nbsp;1 查询 2 导出 3 新增 4 编辑 5 删除 6 保存 7 打印 8 审核 9 反审核 10 复核 11 取消复核<br>
										如:菜单管理模块的查询功能 编号:menu:1" style="color:blue;">
									</e:Label>
								</td>
							</tr>
						</table>
					</e:Panel>
				</td>
			</tr>
	    </table>
	</e:Page>
</body>

<script type="text/javascript">
//init
function ePage_onAfterLoadPage(){
	var tree = $J("DataTree_Menu");
    if (!tree) {
        MsgBox.showWarnMsg("菜单树还未生成！");
        return;
    }
    if (!tree.currentNode) {
    	tree.setCurrentNode();
	}
    tree.expandNode();//展开当前节点
}

//保存
function RecordButton_Save_onClick(){
	Command_Save.execute();
}
//关联菜单对应功能：
function Dataset_Menu_onAfterScroll(dataset){
    var menuId = dataset.getValue("menuId");
    Command_Load.parameters.setValue("menuId",menuId);
    Command_Load.execute();
}

//新增
function RecordButton_Insert_onClick(){
	//取得要增加功能的模块
	var tree = $J("DataTree_Menu");
	var currentNode = tree.getCurrentNode();
	if(currentNode == null){
		MsgBox.showWarnMsg("请先选择要添加功能的菜单模块！");
		return;
	}
	if(currentNode.level <= 1){
		MsgBox.showWarnMsg("不能选择一级菜单！");
		return;
	}
	
	//增加一条记录
	Dataset_Func.insertRecord();
	
	
	//判断当前数据中最大的功能码,获取功能码
	var max = 0;
	var id;
	var clientRecordCount = Dataset_Func.getClientRecordCount();
	for(var i=0; i<clientRecordCount; i++){
		id = Dataset_Func.getRecord(i).getValue("funcId");
		//拆分功能ID为模块编号和功能码
		if(id != null){
			var temp = id.split(":");
			var funcNo = parseInt(temp[1]);//取得功能码
			if(funcNo > max){
				max = funcNo;
			}
		}
	}
	//max做为新增功能记录的默认功能码
	max = parseInt(max) + 1;
	
	
	//获取模块ID
	var menu_id = currentNode.getValue("menuId");
	var currentRecord = Dataset_Func.getCurrentRecord();		
	currentRecord.setValue("menuId", menu_id);
	currentRecord.setValue("funcId", menu_id + ":" + max);
	
	//设置功能编号对应的功能名称
	switch(max){
		case 1 :
			currentRecord.setValue("funcName", "查询");
			break;
		case 2 :
			currentRecord.setValue("funcName", "导出");
			break;
		case 3 :
			currentRecord.setValue("funcName", "新增");
			break;
		case 4 :
			currentRecord.setValue("funcName", "编辑");
			break;
		case 5 :
			currentRecord.setValue("funcName", "删除");
			break;
		case 6 :
			currentRecord.setValue("funcName", "保存");
			break;
		case 7 :
			currentRecord.setValue("funcName", "打印");
			break;
		case 8 :
			currentRecord.setValue("funcName", "审核");
			break;
		case 9 :
			currentRecord.setValue("funcName", "反审核");
			break;
		case 10 :
			currentRecord.setValue("funcName", "复核");
			break;
		case 11 :
			currentRecord.setValue("funcName", "取消复核");
			break;
		default:
			currentRecord.setValue("funcName", "自定义功能");
			break;
	}
}

//单击记录,判断新纪录功能编码才可改动。
function Grid_result_onClick(){
	var element = event.srcElement;
	if(element.isDataCell){
        var currentRecord = element.record;
        if(currentRecord.state == Constant.RECORD.STATE_NEW || currentRecord.state == Constant.RECORD.STATE_INSERT) {
         	currentRecord.dataset.getField("funcId").setReadOnly(false);
        }else{
	        currentRecord.dataset.getField("funcId").setReadOnly(true);
      	}
	}

}

//保存成功
function Command_Save_onExecuteSuccess(command){
	Command_Load.execute();
}

function Command_Save_onExecuteFailure(command){
	Command_Load.execute();
}
	
</script>

</e:View>
</html>
